package com.gezhi.stuserver;

import com.gezhi.stuserver.dto.ResultData;
import com.gezhi.stuserver.feign.ClsFeign;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 定义熔断工厂
 *
 * @author AWG
 */
@Component
public class ClsFeignFallbackFactory implements FallbackFactory<ClsFeign> {


	/**
	 * 为避免在程序执行的过程中出现错误时而导致‘雪崩效应’，通过
	 * SpringCloud 的断路器机制来实现服务的降级，以确保系统在依赖的其他服务出现故障时运行不会受到影响
	 * @param cause 错误
	 * @return 熔断器的提示
	 */
	@Override
	public ClsFeign create(Throwable cause) {
		return new ClsFeign() {
			@Override
			public ResultData findAllClass() {
				ResultData resultData = new ResultData();
				resultData.setCode("10000");
				resultData.setMsg("[服务降级]：班级系统业务繁忙，请稍后重试！");
				return resultData;
			}
		};
	}

}
